<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
    <script
      src="../day08/ajax.js"
      type="text/javascript"
      charset="utf-8"
    ></script>
  </head>
  <body>
    <button>点击我发送请求</button>
    <script type="text/javascript">
      let btn = document.querySelector("button");
      btn.onclick = function () {
        ajax({
          url: "index.php",
        }).then((res) => {
          // console.log(res);
          localStorage.setItem("res", res);
          let data = JSON.parse(res);
          renderDom(data);
        });

        // if(localStorage.getItem("res")){
        // 	let data = JSON.parse(localStorage.getItem("res"));
        // 	renderDom(data);

        // }else{
        // 	ajax({
        // 		url:"get.php"
        // 	}).then(res=>{
        // 		// console.log(res);
        // 		localStorage.setItem("res",res);
        // 		let data = JSON.parse(res);
        // 		renderDom(data);
        // 	})
        // }
      };

      function renderDom(data) {
        let divEle = document.createElement("div");
        divEle.innerHTML = `姓名是：${data.name};年龄是:${data.age}`;
        document.body.appendChild(divEle);
      }
    </script>
  </body>
</html>
